#include "tlc5916.h"

void led_driver_init(void)
{
	//Set outputs
	DDRC |= _BV(ED1) | _BV(ED2) | _BV(SIN) | _BV(SCLK);
	//Initial values
	PORTC &= ~_BV(ED1) | ~_BV(ED2);
	//Set up SPI
	spi_master_init();
}

void display_loop(uint8_t *data, int num_frames)
{
	//Turn outputs on
	PORTC &= ~_BV(ED2);

	int i;
	for(i = 0; i < num_frames; ++i) {
		//Send data
		spi_tx(data[i]);
		//Latch it by pulsing ED1
		PORTC |= _BV(ED1);
		PORTC &= ~_BV(ED1);
		//Sets refresh rate...62.5Hz
		_delay_ms(16);
	}

	//Turns outputs off
	PORTC |= _BV(ED2);
}
